#include <stdio.h>

struct student {
    int num;
    char name[20];
    char sex;
    float score;
};

int main() {


    struct student stu[5] = {{1, "李芳",   'F', 45},
                              {2, "于红",   'F', 62.5},
                              {3, "何万山", 'M', 92.5},
                              {4, "程亚丽", 'M', 87},
                              {5, "王明",   'M', 58}};

    int i, j, n = 5;
    /* 按照分数从高到低排序*/
    for (i = 0; i < n - 1; ++i) {
        for (j = i + 1; j < n; j++)
            if (stu[j].score < stu[i].score)  /* 比较成绩 */
            {
                /*交换数组元素*/
                struct student temp = stu[j];
                stu[j] = stu[i];
                stu[i] = temp;
            }
    }


    // 打印学生信息 遍历
    for (int i = 0; i < 5; i++) {
        printf("学号：%d 姓名：%s 性别：%c 成绩：%.2f\n", stu[i].num, stu[i].name, stu[i].sex, stu[i].score);
    }

}